package com.store.bookstore_backend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
    private ApiInfo commonApiInfo() {
        //配置基本信息
        Contact adam = new Contact("Adam", "https://github.com/adam", "adam@gmail.com");
        return new ApiInfoBuilder()
                //标题
                .title("杰普网上商城项目")
                .description("杰普网上上传项目用户端系统 接口管理文档")
                //基本信息
                .contact(adam)
                .version("1.0.0")
                .build();
    }

    @Bean(value = "dockerBeanAdmin")
    public Docket dockerBeanAdmin() {
        //指定使用Swagger2规范
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(commonApiInfo())
                //分组名称
                .groupName("后台接口分组")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.itwenke.springbootdemo.knife4j.admin"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    @Bean
    public Docket dockerBeanFront() {
        //指定使用Swagger2规范
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(commonApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.store.bookstore_backend.web"))
                .paths(PathSelectors.any())
                .build();
    }
}
